package devmento.gae.dao;


import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Component;

import devmento.gae.model.Employee;

@Component
public class EmployeeDao {
	private Map<String, Employee> repository = new HashMap();
	
	public EmployeeDao(){
		Employee emp01 = new Employee("0001", "Park", "ChanHo");
		repository.put(emp01.getEmployeeId(), emp01);
		Employee emp02 = new Employee("0002", "Hong", "GilDong");
		repository.put(emp02.getEmployeeId(), emp02);
		Employee emp03 = new Employee("0003", "Kim", "Yuna");
		repository.put(emp03.getEmployeeId(), emp03);
	}
	
	public Employee find(String employeeId){
		return repository.get(employeeId);
	}
	
	public void save(Employee emp){
		repository.put(emp.getEmployeeId(), emp);
	}
	
	public void delete(String employeeId){
		repository.remove(employeeId);
	}
	
	public Employee[] findAll(){
		Collection<Employee> coll = repository.values();
		Employee[] employees = null;
	    employees = coll.toArray(new Employee[coll.size()]);
		return employees;
	}
}
